package com.anti.modular.bus.roomexpenses.controller;

import com.anti.commom.annotation.BusinessLog;
import com.anti.commom.annotation.Permission;
import com.anti.commom.enums.LogAnnotionOpTypeEnum;
import com.anti.commom.api.Result;
import com.anti.jdbc.support.page.PageParam;
import com.anti.modular.bus.roomexpenses.param.RoomExpensesParam;
import com.anti.modular.bus.roomexpenses.service.RoomExpensesService;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;

/**
 * 房间费用表控制器
 *
 * @author anti
 * @date 2021-04-18 17:08:44
 */
@RestController
@RequestMapping("roomExpenses")
public class RoomExpensesController {

    @Resource
    private RoomExpensesService roomExpensesService;

    /**
     * 查询房间费用表
     *
     * @author anti
     * @date 2021-04-18 17:08:44
     */
    @GetMapping("page")
    @BusinessLog(title = "房间费用表_查询", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result page(PageParam pageParam, RoomExpensesParam roomExpensesParam) {
        return Result.data(roomExpensesService.page(pageParam,roomExpensesParam));
    }

    /**
     * 添加房间费用表
     *
     * @author anti
     * @date 2021-04-18 17:08:44
     */
    @Permission
    @PostMapping("add")
    @BusinessLog(title = "房间费用表_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public Result add(@RequestBody @Validated(RoomExpensesParam.add.class) RoomExpensesParam roomExpensesParam) {
            roomExpensesService.add(roomExpensesParam);
        return Result.success("新增成功");
    }

    /**
     * 删除房间费用表
     *
     * @author anti
     * @date 2021-04-18 17:08:44
     */
    @Permission
    @PostMapping("delete")
    @BusinessLog(title = "房间费用表_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public Result delete(@RequestBody @Validated(RoomExpensesParam.delete.class) RoomExpensesParam roomExpensesParam) {
            roomExpensesService.delete(roomExpensesParam);
        return Result.success("删除成功");
    }

    /**
     * 编辑房间费用表
     *
     * @author anti
     * @date 2021-04-18 17:08:44
     */
    @Permission
    @PostMapping("edit")
    @BusinessLog(title = "房间费用表_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public Result edit(@RequestBody @Validated(RoomExpensesParam.edit.class) RoomExpensesParam roomExpensesParam) {
            roomExpensesService.edit(roomExpensesParam);
        return Result.success("修改成功");
    }

    /**
     * 查看房间费用表
     *
     * @author anti
     * @date 2021-04-18 17:08:44
     */
    @GetMapping("detail")
    @BusinessLog(title = "房间费用表_查看", opType = LogAnnotionOpTypeEnum.DETAIL)
    public Result detail(@Validated(RoomExpensesParam.detail.class) RoomExpensesParam roomExpensesParam) {
        return Result.data(roomExpensesService.detail(roomExpensesParam));
    }

    /**
     * 房间费用表列表
     *
     * @author anti
     * @date 2021-04-18 17:08:44
     */
    @GetMapping("list")
    @BusinessLog(title = "房间费用表_列表", opType = LogAnnotionOpTypeEnum.QUERY)
    public Result list(RoomExpensesParam roomExpensesParam) {
        return Result.data(roomExpensesService.list(roomExpensesParam));
    }

    /**
     * 获取房间费用列表
     * @param roomId
     * @return
     */
    @GetMapping("getExpensesListByRoomId/{roomId}")
    public Result getExpensesListByRoomId(@PathVariable(name = "roomId") Long roomId) {
        return Result.data(roomExpensesService.getExpensesListByRoomId(roomId));
    }

    @GetMapping("getExpensesListByLeaseId/{leaseId}")
    public Result getExpensesListByLeaseId(@PathVariable(name = "leaseId") Long leaseId) {
        return Result.data(roomExpensesService.getExpensesListByLeaseId(leaseId));
    }

}
